﻿(function() {
    if (!window.XJLib) { window.XJLib = {}; };

    function getBrowserWindowSize() {
        var de = document.documentElement;
        return {
            "width": (window.innerWidth || (de && de.clientWidth) || document.body.clientWidth),
            "height": (window.innerHeight || (de && de.clientHeight) || document.body.clientHeight)
        };
    };

    function myLogger(id) {
        id = id || 'XJLibLogWindow';

        var logWindow = null;
        var createWindow = function() {
            var browserWindowSize = XJLib.getBrowserWindowSize();
            //窗口左上角坐标
            var top = ((browserWindowSize.height - 200) / 2) || 0;
            var left = ((browserWindowSize.width - 200) / 2) || 0;
            //创建日志窗口的DOM节点
            //使用受保护的logWindow属性维护引用
            logWindow = document.createElement("UL");
            //指定ID值,以便必要时在DOM树中能够识别它
            logWindow.setAttribute("id", id);
            //设置固定大小并允许窗口内容滚动
            logWindow.style.position = 'absolute';
            logWindow.style.top = top + "px";
            logWindow.style.left = left + "px";
            logWindow.style.width = "200px";
            logWindow.style.height = "200px";
            logWindow.style.overflow = "scroll";
            //设置一些样式                
            logWindow.style.padding = "0";
            logWindow.style.margin = "0";
            logWindow.style.border = "1px solid black";
            logWindow.style.backgroundColor = "white";
            logWindow.style.listStyle = "none";
            logWindow.style.font = "10px/10px Verdana, Tahoma, Sans";

            document.body.appendChild(logWindow);
        };
        this.writeRaw = function(message) {
            if (!logWindow) createWindow();
            var li = document.createElement("LI");
            li.style.padding = "2px";
            li.style.border = "0";
            li.style.borderBottom = "1px dotted black";
            li.style.margin = "0";
            li.style.color = "#000";
            li.style.font = "9px/9px Verdana,Tahoma,Sans";
            if (typeof message == "undefined") {
                li.appendChild(document.createTextNode("message was undefined"));
            }
            else if (typeof li.innerHTML != undefined) {
                li.innerHTML = message;
            }
            else {
                li.appendChild(document.createTextNode(message));
            }
            logWindow.appendChild(li);
            return true;
        };
    }
    myLogger.prototype = {
        write: function(message) {
            if (typeof message == "string" && message.length == 0) {
                return this.writeRaw("XJLib.log:null message");
            }
            if (typeof message != "string") {
                if (message.toString()) return this.writeRaw(message.toString());
                else return this.writeRaw(typeof message);
            }
            message = message.replace(/</g, "&lt;").replace(/>/g, "&gt;")
            return this.writeRaw(message);
        },
        header: function(message) {
            message = '<span style="color:white;background-color:black;font-weight:bold;padding:0px 5px;">' + message + '</span>';
            return this.writeRaw(message);
        }
    };
    
    window.XJLib.getBrowserWindowSize = getBrowserWindowSize;
    window.XJLib.log = new myLogger();
})();

(function() {
    

    
})();